package com.nanyang.tms.controller.company;

import com.nanyang.common.core.annotation.BindParam;
import com.nanyang.common.core.dict.CommonEnum;
import com.nanyang.common.core.domain.ApiResult;
import com.nanyang.common.core.exception.ServiceException;
import com.nanyang.common.core.page.PageBean;
import com.nanyang.tms.api.dto.request.companydeclare.CompanyDeclareAddRequest;
import com.nanyang.tms.api.dto.request.companydeclare.CompanyDeclareDelRequest;
import com.nanyang.tms.api.dto.request.companydeclare.CompanyDeclareQueryRequest;
import com.nanyang.tms.api.dto.request.companydeclare.CompanyDeclareUpdateRequest;
import com.nanyang.tms.api.dto.response.companydeclare.CompanyDeclarePageResponse;
import com.nanyang.tms.api.dto.response.companydeclare.CompanyDeclareResponse;
import com.nanyang.tms.api.service.companydeclare.CompanyDeclareRpcService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@RestController
@RequestMapping("/companydeclare")
public class CompanyDeclareController {

    @Reference(version = "1.0.0", timeout = 10000, check = false)
    private CompanyDeclareRpcService companyDeclareRpcService;

    /**
     * <p>listCompanyDeclare</p>
     * <p>Description:查询列表</p>
     *
     * @param param
     * @return
     */
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    @BindParam
    public ApiResult<PageBean<CompanyDeclarePageResponse>> listCompanyDeclare(@BindParam @RequestBody CompanyDeclareQueryRequest param) {
        ApiResult<PageBean<CompanyDeclarePageResponse>> apiResult = companyDeclareRpcService.listCompanyDeclare(param);
        if (apiResult.getCode() == CommonEnum.SYSTEM_EXCEPTION.getCode()) {
            throw new ServiceException(CommonEnum.SYSTEM_EXCEPTION.getCode(), apiResult.getMessage());
        }
        return apiResult;
    }
    /**
     * <p>listCompanyDeclare</p>
     * <p>Description:查询根据编码</p>
     *
     * @param param
     * @return
     */
    @RequestMapping(value = "/selectByCode", method = RequestMethod.POST)
    @BindParam
    public ApiResult<CompanyDeclareResponse> selectByCode(@BindParam @RequestBody CompanyDeclareQueryRequest param) {
        ApiResult<CompanyDeclareResponse> apiResult = companyDeclareRpcService.selectByCode(param);
        if (apiResult.getCode() == CommonEnum.SYSTEM_EXCEPTION.getCode()) {
            throw new ServiceException(CommonEnum.SYSTEM_EXCEPTION.getCode(), apiResult.getMessage());
        }
        return apiResult;
    }

    /**
     * 添加-前台
     * @param param
     * @return
     */

    @RequestMapping(value = "/save", method = RequestMethod.POST)
    @BindParam
    public ApiResult<Boolean> saveProduct(@BindParam @RequestBody @Valid CompanyDeclareAddRequest param) {
        ApiResult<Boolean> apiResult = companyDeclareRpcService.saveCompanyDeclare(param);
        if (apiResult.getCode() == CommonEnum.SYSTEM_EXCEPTION.getCode()) {
            throw new ServiceException(CommonEnum.SYSTEM_EXCEPTION.getCode(), apiResult.getMessage());
        }
        return apiResult;
    }
    /**
     * 修改-前台
     * @param param
     * @return
     */

    @RequestMapping(value = "/update", method = RequestMethod.POST)
    @BindParam
    public ApiResult<Boolean> updateCompanyDeclare(@BindParam @RequestBody @Valid CompanyDeclareUpdateRequest param) {
        ApiResult<Boolean> apiResult = companyDeclareRpcService.updateCompanyDeclare(param);
        if (apiResult.getCode() == CommonEnum.SYSTEM_EXCEPTION.getCode()) {
            throw new ServiceException(CommonEnum.SYSTEM_EXCEPTION.getCode(), apiResult.getMessage());
        }
        return apiResult;
    }
    /**
     * 删除-前台
     * @param param
     * @return
     */

    @RequestMapping(value = "/del", method = RequestMethod.POST)
    @BindParam
    public ApiResult<Boolean> delCompanyDeclare(@BindParam @RequestBody @Valid CompanyDeclareDelRequest param) {
        ApiResult<Boolean> apiResult = companyDeclareRpcService.delCompanyDeclare(param);
        if (apiResult.getCode() == CommonEnum.SYSTEM_EXCEPTION.getCode()) {
            throw new ServiceException(CommonEnum.SYSTEM_EXCEPTION.getCode(), apiResult.getMessage());
        }
        return apiResult;
    }
}
